#pragma once
#include <vector>
#include <string>
#include "geometry.h"
#include "tgaimage.h"

class Model {
    std::vector<vec3> verts{};     // array of vertices
    std::vector<vec2> tex_coord{}; // per-vertex array of tex coords
    std::vector<vec3> norms{};     // per-vertex array of normal vectors
    std::vector<int> facet_vrt{};
    std::vector<int> facet_tex{};  // per-triangle indices in the above arrays
    std::vector<int> facet_nrm{};
    TGAImage diffusemap{};         // diffuse color texture
    TGAImage normalmap{};          // normal map texture
    TGAImage specularmap{};        // specular map texture
    static void load_texture(const std::string &filename, const std::string &suffix, TGAImage &img);
public:
    explicit Model(const std::string &filename);
    [[nodiscard]] int nverts() const;
    [[nodiscard]] int nfaces() const;
    [[nodiscard]] vec3 normal(int iface, int nthvert) const; // per triangle corner normal vertex
    [[nodiscard]] vec3 normal(const vec2 &uvf ) const;                     // fetch the normal vector from the normal map texture
    [[nodiscard]] vec3 vert(int i) const;
    [[nodiscard]] vec3 vert(int iface, int nthvert) const;
    [[nodiscard]] vec2 uv(int iface, int nthvert) const;
    [[nodiscard]] const TGAImage& diffuse()  const { return diffusemap;  }
    [[nodiscard]] const TGAImage& specular() const { return specularmap; }
};

